package com.abdeafan.anekdot_01;


import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class MyActivity extends FragmentActivity {

    static final String TAG = "myLogs";
    static final int PAGE_COUNT = 10;
    ViewPager pager;
    PagerAdapter pagerAdapter;
    int anekdot_list_len;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        Resources anekdot_list_res = getResources();
        final String[] anekdot = anekdot_list_res.getStringArray(R.array.anekdot_list);
        anekdot_list_len = anekdot.length;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        pager = (ViewPager) findViewById(R.id.pager);
        pagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
        pager.setAdapter(pagerAdapter);
        pager.setOnPageChangeListener(new OnPageChangeListener()
        {
            @Override
            public void onPageSelected(int position)
            {
                Log.d(TAG, "onPageSelected, position = " + position);
            }
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
            {
            }
            @Override
            public void onPageScrollStateChanged(int state)
            {
            }
        });
    }
    private class MyFragmentPagerAdapter extends FragmentPagerAdapter
    {
        public MyFragmentPagerAdapter(FragmentManager fm)
        {
            super(fm);
        }
        @Override
        public Fragment getItem(int position)
        {
            return PageFragment.newInstance(position);
        }
        @Override
        public int getCount()
        {
            return anekdot_list_len;
//            return PAGE_COUNT;
        }
    }
}